import Login from '../pages/login/Login'
import Notfound from '../pages/404/Notfound'
import Permission from '../pages/permission/Permission'
import Role from '../pages/role/Role'
import Users from '../pages/users/Users'
import Home from '../pages/home/Home'
import Questions from '../pages/questions/Questions'
import CreateQuestion from '../pages/createQuestion/CreateQuestion'
import PermissionRoute from './PermissionRoute'
import Forbidden from '../pages/403/Forbidden'
import GroupList from '../pages/groupList/GroupList' 
import Layout from "../Layout/Layout"
import { Navigate } from 'react-router-dom'

const routes = [
  {
    path: '/',
    element: <Home />,
    layout: true,
  },
  // 班级管理
  {
    path: '/manage-group',
    element: <Navigate to="/manage-group/group-list" />
  },
  {
    path: '/manage-group/group-list',
    element: <GroupList />,
    layout: true,
    permission: true
  },
  // 系统管理
  {
    path: '/userManage',
    element: <Navigate to="/userManage/manage-page" />
  },
  {
    path: '/userManage/manage-page', // 用户管理
    element: <Users />,
    layout: true,
    permission: true
  },
  {
    path: '/userManage/menuManage', // 权限管理
    element: <Permission />,
    layout: true,
    permission: true
  },
  {
    path: '/userManage/system', // 角色管理
    element: <Role />,
    layout: true,
    permission: true
  },
  // 试题管理
  {
    path: '/question',
    element: <Navigate to="/question/item-bank" />
  },
  {
    path: '/question/item-bank', // 试题库
    element: <Questions />,
    layout: true,
    permission: true
  },
  {
    path: '/question/create-item', // 创建试题
    element: <CreateQuestion />,
    layout: true,
    permission: true
  },
  {
    path: '/user/login',
    element: <Login />
  },
  {
    path: '/403',
    element: <Forbidden />
  },
  {
    path: '*',
    element: <Notfound />
  }
]


const routerConfig = routes.map(route => {
  if (route.layout) {
    route.element = <Layout>{route.element}</Layout>
  }
  if (route.permission) {
    route.element = <PermissionRoute>{route.element}</PermissionRoute>
  }
  return route
})

export default routerConfig